%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%openDACS projects%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Main optimization routine for A-IGZO TETs
%%% Print parameters or self-generate Verilog-A
%%% About a-IGZO devices and models,pls refer 10.1063/1.4922181,10.1109/TED.2021.3054359
%%% developed by Jingrui Guo,Lingfei Wang, and Ling Li from IME-CAS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function self_coded(coeff_op_final)
global input_parms
format shortE
col_dim=1;
format_string = cell(col_dim,1);
% outfile_name = ['self-coded/',input('Enter the file name to store results::-> ', 's'),'.va'];
outfile_name = 'self-coded/odtftv1.va';
fileID = fopen(outfile_name, 'w');
%%%%initial
initial_index=3;
ini_print = cell(initial_index,1);
ini_print{1} = ['`include "constants.vams"'];
ini_print{2} = ['`include "disciplines.vams"'];
ini_print{3} = ['module ODTFT(d,g,s);'];
for i=1:initial_index
fprintf(fileID, '%8s\n',ini_print{i});
end
%%%% write parameters
input_final=[input_parms(1:6);coeff_op_final];
row_dim = length(input_final);
col_dim = 1;
row_labels_final = cell(row_dim,1);
row_labels_final{1} = ['parameter real T='];
row_labels_final{2} = ['parameter real l='];     
row_labels_final{3} = ['parameter real w='];
row_labels_final{4} = ['parameter real Ci='];
row_labels_final{5} = ['parameter real Fs='];
row_labels_final{6} = ['parameter real lleak='];
row_labels_final{7} = ['parameter real TA='];
row_labels_final{8} = ['parameter real Nt='];
row_labels_final{9} = ['parameter real n='];
row_labels_final{10} =['parameter real m='];
row_labels_final{11} =['parameter real ss='];
row_labels_final{12} = ['parameter real Vfb='];
row_labels_final{13} = ['parameter real Ue='];
row_labels_final{14} = ['parameter real y='];
row_labels_final{15} =['parameter real ScaleVd='];
row_labels_final{16} =['parameter real ScaleVg='];
row_labels_final{17} =['parameter real FVd=']
for nC = 1:col_dim
    format_string{nC} = ['%e'];
end
for navg=1:row_dim
    fprintf(fileID, '    %8s', row_labels_final{navg});
    fprintf(fileID, [format_string{:}], input_final(navg,:));
    fprintf(fileID, [' from [-inf:inf];', '\n'], input_final(navg,:));
end
%%%% write the rest
fidin=fopen('va_body','r');
while ~feof(fidin)
fprintf(fileID,[fgetl(fidin),'\n']);    
end
fclose('all');
end


